

use "$data/clean/clean_main_complete.dta" , replace


tempfile main
save `main', replace

clear all
eststo clear
estimates drop _all

loc columns = 6

set obs 10
gen x = 1
gen y = 1

forval i = 1/`columns' {
	eststo col`i': reg x y
} 

loc count = 1

loc statnames ""
loc varlabels ""

/* Custom fill cells */



use `main', clear

label var comment_any  "Any comment"
label var comment_constructive  "Constructive comment"
label var comment_nonsense "Nonsense comment"
label var comment_length_wins "Comment length"

gen pana=.
gen panb=.
gen panf=.
gen pand=.
gen pane=.
gen pang=.
gen intt= .
gen empt =. 
gen part_aff = .

label var pana "\underline{Individual level characteristics} " 
label var panb "\underline{Prior experience} " 
label var pand "\underline{Post treatment attitudes (control)}" 
label var pane "\underline{Post treatment intentions (control)}"  
label var panf "\underline{Post treatment behavior (control)}"  
label var pang "\underline{Provided comments (all treatment)}"  
label var empt " "
  
  foreach yvar of varlist pana  female age party_member  member_years voice_prior ///
 empt panb d_experience_campaign pre_doortodoor pre_days_doortodoor pre_posters pre_booth pre_online pre_call pre_friends pre_others  empt   {
	 sum `yvar', d
	if `r(N)'!=0 {
	cap: estadd loc thisstat`count' = string(`r(mean)', "%9.2f"): col1
	cap: estadd loc thisstat`count' = string(`r(sd)', "%9.2f"): col2
	cap: estadd loc thisstat`count' = string(`r(p50)', "%9.2f"): col3
	cap: estadd loc thisstat`count' = string(`r(min)', "%9.0f"): col4
	cap: estadd loc thisstat`count' = string(`r(max)', "%9.0f"): col5
	cap: estadd loc thisstat`count' = `r(N)' : col6 
	}

	/* Row Labels */
	
	loc thisvarlabel: variable label `yvar'
	local varlabels "`varlabels' "`thisvarlabel'" "
	loc statnames "`statnames' thisstat`count'"
	loc count = `count' + 1

}



  
  foreach yvar of varlist pand  fs_engagement fs_connected fs_voice fs_interest fs_effective ///
 empt pane n_intendedact  int_no_plans int_doortodoor  int_days_doortodoor int_posters int_booth int_online int_call int_friends int_others  empt   panf any_doors doors_wins empt {
	qui sum `yvar' if control==1, d
	if `r(N)'!=0 {
	cap: estadd loc thisstat`count' = string(`r(mean)', "%9.2f"): col1
	cap: estadd loc thisstat`count' = string(`r(sd)', "%9.2f"): col2
	cap: estadd loc thisstat`count' = string(`r(p50)', "%9.2f"): col3
	cap: estadd loc thisstat`count' = string(`r(min)', "%9.0f"): col4
	cap: estadd loc thisstat`count' = string(`r(max)', "%9.0f"): col5
	cap: estadd loc thisstat`count' = `r(N)' : col6 
	}

	/* Row Labels */
	
	loc thisvarlabel: variable label `yvar'
	local varlabels "`varlabels' "`thisvarlabel'" "
	loc statnames "`statnames' thisstat`count'"
	loc count = `count' + 1

}

  foreach yvar of varlist pang  comment_any comment_nonsense  comment_constructive comment_length_wins  empt   {
	qui sum `yvar', d
	if `r(N)'!=0 {
	cap: estadd loc thisstat`count' = string(`r(mean)', "%9.2f"): col1
	cap: estadd loc thisstat`count' = string(`r(sd)', "%9.2f"): col2
	cap: estadd loc thisstat`count' = string(`r(p50)', "%9.2f"): col3
	cap: estadd loc thisstat`count' = string(`r(min)', "%9.0f"): col4
	cap: estadd loc thisstat`count' = string(`r(max)', "%9.0f"): col5
	cap: estadd loc thisstat`count' = `r(N)' : col6 
	}

	/* Row Labels */
	
	loc thisvarlabel: variable label `yvar'
	local varlabels "`varlabels' "`thisvarlabel'" "
	loc statnames "`statnames' thisstat`count'"
	loc count = `count' + 1

}





/* Footnotes */

loc prehead "\begin{tabular}{l*{`columns'}{c}} \toprule"

loc postfoot "\bottomrule \end{tabular}"



esttab col* using "$output/sumstats_main", booktabs cells(none) nonum nogap mtitle("Mean" "SD" "Median" "Min." "Max." "Obs.") ///
 stats(`statnames', labels(`varlabels'))  prehead("`prehead'") postfoot("`postfoot'") compress wrap replace

eststo clear




